import java.util.Scanner;

public class BankAccount {
    private String accountNumber;
    private String accountHolder;
    private int balance;

    public BankAccount() {

    }

    public BankAccount(String accountNumber, String accountHolder,int balance) {
        this.accountNumber = accountNumber;
        this.accountHolder = accountHolder;
        this.balance = balance;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public void setAccountHolder(String accountHolder) {
        this.accountHolder = accountHolder;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public String getAccountHolder() {
        return accountHolder;
    }

    public int getBalance() {
        return balance;
    }

    public boolean MakeBalance(int money) {
        if (money > 0) {
            this.balance += money;
            return true;
        } else {
            System.out.println("你输入的金额不对！");
            return false;
        }
    }

    public boolean SaveBalance(int money) {
        if (money < 0) {
            System.out.println("你输入的金额不对！");
            return false;
        } else {
            if (balance < money){
                System.out.println("余额不足，你心里没数嘛");
                return false;
            }
           this.balance -= money;
            return true;
        }
    }

    public String info(){
        return "账户名称：" + this.accountNumber + ",账户编号：" + this.accountHolder +"，账户余额：" + this.balance;
    }
}
class BankAccountTest{
    static Scanner sc = new Scanner(System.in);
    static BankAccount bankAccount = new BankAccount();
    public static void main(String[] args) {
        while (true) {
            menu();
            System.out.println("请输入你要进行的操作，输入序号即可");
            int op = sc.nextInt();
            switch (op) {
                case 1 -> showInfo();
                case 2 -> saveMoney();
                case 3 -> drawMoney();
                case 4 -> {
                    System.out.println("推出成功");
                    return;
                }
            }
        }
    }
    //显示菜单
    public static void menu(){
        System.out.println("******************");
        System.out.println("1. 查看账户信息");
        System.out.println("2. 存款");
        System.out.println("3. 取款");
        System.out.println("4. 退出");
        System.out.println("******************");
    }
    public static void showInfo(){
        bankAccount.setAccountNumber("100210504");
        bankAccount.setAccountHolder("阿坤");
        bankAccount.setBalance(6666);
        System.out.println(bankAccount.info());
    }
    public static void saveMoney() {
        System.out.println("请输入存款金额");
        int money = sc.nextInt();
        if (bankAccount.MakeBalance(money)) {
            System.out.println("存款成功" + money + "， 当前余额" + bankAccount.getBalance());
        } else {
            System.out.println("存款失败!" );
        }
    }
    public static void drawMoney(){
        System.out.println("请输入取款金额");
        int money = sc.nextInt();
        if (bankAccount.SaveBalance(money)) {
            System.out.println("取款成功" + money + "， 当前余额" + bankAccount.getBalance());
        } else {
            System.out.println("取款失败!" );
        }
    }

}
